import { ElMessageBox, ElMessage, ElLoading } from 'element-plus'

/**
 * 询问对话框
 * @param {*} msg
 */
export function aConfirm(msg, customStyle = {}, options) {
    return ElMessageBox.confirm(msg, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        dangerouslyUseHTMLString: true,
        customStyle,
        ...options,
    })
}

/**
 * 一般信息 确认动作
 * @param {*} msg
 * @param {*} customStyle
 */
export function aInfo(msg, customStyle = {}, options) {
    return new Promise((resolve) => {
        ElMessageBox.alert(msg, '提示', {
            confirmButtonText: '确认',
            type: 'info',
            callback: resolve,
            dangerouslyUseHTMLString: true,
            customStyle,
            ...options,
        })
    })
}

/**
 * 成功信息 确认动作
 * @param {*} msg
 * @param {*} customStyle
 */
export function aSuccess(msg, customStyle = {}, options) {
    const { width, ...style } = customStyle
    const _style = {
        ...style,
        width
    }
    if(width) {
        _style['--el-messagebox-width'] = width
    }
    return new Promise((resolve) => {
        ElMessageBox.alert(msg, '提示', {
            confirmButtonText: '确认',
            type: 'success',
            dangerouslyUseHTMLString: true,
            callback: resolve,
            customStyle: _style,
            ...options,
        })
    })
}

/**
 * 错误信息 确认动作
 * @param {*} msg
 * @param {*} callback
 */
export function aError(msg, customStyle = {}, options) {
    return new Promise((resolve) => {
        ElMessageBox.alert(msg, '提示', {
            confirmButtonText: '确认',
            type: 'error',
            dangerouslyUseHTMLString: true,
            callback: resolve,
            customStyle,
            ...options,
        })
    })
}

/**
 * 警告信息 确认动作
 * @param {*} msg
 * @param {*} customStyle
 */
export function aWarn(msg, customStyle = {}, options) {
    return new Promise((resolve) => {
        ElMessageBox.alert(msg, '提示', {
            confirmButtonText: '确认',
            type: 'warning',
            dangerouslyUseHTMLString: true,
            callback: resolve,
            customStyle,
            ...options,
        })
    })
}

/**
 * 普通信息提醒
 * @param {*} msg
 * @returns
 */
export function tInfo(msg) {
    return ElMessage.info(msg)
}

/**
 * 成功信息提醒
 * @param {*} message
 * @returns
 */
export function tSuccess(message) {
    return ElMessage({
        message,
        type: 'success',
        dangerouslyUseHTMLString: true
    })
}

/**
 * 错误信息提醒
 * @param {*} message
 * @returns
 */
export function tError(message) {
    return ElMessage({
        message,
        type: 'error',
        dangerouslyUseHTMLString: true
    })
}

/**
 * 警告信息提醒
 * @param {*} message
 * @returns
 */
export function tWarn(message) {
    return ElMessage({
        message,
        type: 'warning',
        dangerouslyUseHTMLString: true
    })
}

/**
 * loading 层，防止误操作
 * 初始化后调用，需要代码中手动关闭
 * @param {*} msg
 * @returns
 */
export function tLoading(msg) {
    return ElLoading.service({
        fullscreen: true,
        text: msg,
        body: true,
        customClass: 'custom-el-loading',
        background: 'rgba(255,255,255,0.95)'
    })
}
